<?php

 /**
  * @package JooS
  * @subpackage PHPackager
  */

  require_once "JooS/Helper/Abstract.php";

  class JooS_PHPackager_Helper_Cleanup extends JooS_Helper_Abstract {
    public function __invoke() {
      require_once "JooS/Config.php";
      require_once "JooS/Loader.php";
      require_once "JooS/PHPackager/FS.php";

      $fileSystem = JooS_PHPackager_FS::getInstance();
      $instance = $this->getSubject();

      $files = $instance->getFiles();
      if (is_array($files)) {
        foreach($files as $file) {
          $realPath = JooS_Config::PHPackager()->path() . DIRECTORY_SEPARATOR . $file;

          $fileSystem->delete($realPath);
        }
      }

      $className = get_class($instance);
      $fileSystem->delete(JooS_Loader::getRealPath($className));
      $fileSystem->delete(JooS_Loader::getRealPath($className, "zip"));

      $envName = $instance->getEnvironmentConfigName();
      $fileSystem->delete( JooS_Loader::getRealPath(JooS_Config::getClassName($envName)) );
    }
  }
